package com.example.myapplication.tack_20;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_20.data.DetailsData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import javax.xml.transform.OutputKeys;

public class DerailsActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView imags;
    private TextView text;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_20_activity_derails);
        init();
        exit_();
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        getDetails(id);
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DerailsActivity.this.finish();
            }
        });
    }

    private void getDetails(String id) {
        String url = "prod-api/api/volunteer-service/news/" +id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, DetailsData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                DetailsData data = (DetailsData)obj;
                if(data.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(DerailsActivity.this).load(OkHttpTool.URL + data.getData().getImgUrl()).into(imags);
                            text.setText(data.getData().getSummary());
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        imags = findViewById(R.id.imags);
        text = findViewById(R.id.text);
    }
}